import axios from 'axios'

// 路由匹配
export const createMenuTree = (params) => {
  // 菜单列表页面展示
  const route =
  {
    path: '/main',
    name: 'main',
    // 特别注意layout公共组件不能使用前端工程化导入
    component: import('../views/LayOut/index.vue'),
    children: []
  }
  route.children = params.map((item) => {
    item.component = require(`@/views/LayOut/${item.component}/index.vue`)
    return item
  })
  return route
}

// 动态改变请求头要求的请求参数类型
// 一般分为三种：application/x-www-form-urlencoded (表单默认)、application/json (json数据)、multipart/form-data (formData类型：一般用于流数据，eg：文件上传、图片上传)
export const httpHeadersType = (url, params, method = 'GET', headerType = 'json') => {
  let baseURL = ''; let headers = {}; let data = {}

  switch (process.env.NODE_ENV) {
    // 开发环境
    case 'development':
      baseURL = '/apiProxy'
      break
    // 正式环境
    case 'production':
      baseURL = 'http://47.97.71.79:8090/'
      break
    // 测试环境
    case 'testing':
      baseURL = 'http://47.97.71.79:8090/'
      break
  }
  axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
  axios.defaults.headers['Cache-Control'] = 'no-cache'
}
